import { getGlobalData } from '../../configuration/globaldata'
import { avater, dealImgUrl } from '../../configuration/staticimg'

export const formatDataJobView = entry => {
  try {
    let list = []
    entry.map(data => {
      let basicInfo = data.basicInfoModel || {}
      let distance = `${(data.distance / 1000).toFixed(2)}km`
      list.push({
        collection_id: data.collection_id,
        id: data.id,
        resumeCount: data.resumeCount,
        viewCount: data.resumeCount,
        extra1: data.extra1,
        isOld: data.isOld,
        name: basicInfo.name,
        type: basicInfo.type,
        salary: basicInfo.salary,
        category: basicInfo.category,
        // workHours: basicInfo.workHours,
        workPlace: data.postWorkLocations,
        workContent: basicInfo.workContent,
        settlementMethod: basicInfo.settlementMethod,
        unitMethod: basicInfo.unit,
        companyId: data.companyId,
        practiceLabel: basicInfo.practiceLabel,
        isFast: data.isFast,
        date: data.gmtCreate,
        distance
      })
    })
    return list
  } catch (e) {
    return []
  }
}

export const formatDataJobViewRight = (entry, search) => {
  // try {
  let entryNew = []
  entry.map(data => {
    let comprehensive = search ? JSON.parse(data.objective[0]) : JSON.parse(data.comprehensive)
    let educationsingle = getGlobalData('education')
    let educationData = educationsingle[ (data.education >= 10 ? Math.floor(data.education / 10) : data.education) - 1 ]
    entryNew.push({
      archiveId: data.archiveId,
      id: data.userId,
      userName: data.userName,
      education: data.education
        ? educationData && educationData.name || ''
        : '',
      isOld: data.isOld, // 老数据判断字段
      gender: data.gender || data.extra,
      intro: data.intro || data.skillDescription,
      userAvator: data.avatarUrl ? dealImgUrl(data.avatarUrl) : avater(data.gender || data.extra, data.userId || data.id || data.archiveId),
      workCategory: comprehensive.workCategory,
      workNature: Array.isArray(comprehensive.workNature)
        ? comprehensive.workNature
        : [comprehensive.workNature]
    })
  })
  return entryNew
  // } catch (ex) {
  //   return []
  // }
}
